<?php
/*
* $Author ：PHPYUN开发团队
*
* 官网: http://www.phpyun.com
*
* 版权所有 2009-2018 宿迁鑫潮信息技术有限公司，并保留所有权利。
*
* 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
 */


class index_controller extends common{
	function index_action(){
     
       @session_start();
       //print_R($_SESSION);
        //hjl test start
         //global $db;
         //$cache_array = $db->cacheget();
        //var_dump($_COOKIE);
       //hjl test end
	   //miracle引入分享类
		$JobS = $this->MODEL("job_share");

		if(!$this->config['did'] && $this->config['sy_gotocity']=='1' && !$_COOKIE['gotocity']){
			include(PLUS_PATH."domain_cache.php");
			go_to_city($site_domain);
		}
		$this->get_moblie();

		$this->seo("index");
		$this->yunset('indexnav',1);

		$share_list = $JobS->get_index_share(30);
		$share_num = $JobS->get_share_num();
		$total_money = $JobS->get_total_money();
		$this->yunset('share_list',$share_list);
		$this->yunset('share_num',$share_num);
		$this->yunset('total_money',$total_money);
		
		$this->yuntpl(array('wap/index'));
		
	}

	function loginout_action(){
		$this->cookie->unset_cookie();
		$this->wapheader('index.php');
	}


    //hjl  智能推荐默认获取附近工作（原理：根据距离升序排序）
   
    function joblist_action(){
         global $db;
         $cache_array = $db->cacheget();
        //hjl test stast
       /* echo json_encode(array('list'=>array(
            array('name'=>'zhansna')
        )));die;*/
        //hjl test end

		$this->get_moblie();
        $JobM=$this->MODEL('job');
        
        $select="`id`,`uid`,`name`,`minsalary`,`maxsalary`,`lastupdate`,`provinceid`,`cityid`,`exp`,`edu`,`label`,6371 * acos(cos(radians(".$_POST['y'].")) * cos(radians(`y`)) * cos(radians(`x`) - radians(".$_POST['x'].")) + sin(radians(".$_POST['y'].")) * sin(radians(`y`))) AS `distance`,`bounty`,`job_pay`";


      
        $page = $_POST['page']?$_POST['page']:1;
        if ($this->config['sy_indexpage']){
            $indexpagenum = ceil($this->config['sy_indexpage']/10);
            if($page>$indexpagenum){
                $page=$indexpagenum;
            }
        }
        $pagenav=($page-1)*3;
        $limit="$pagenav,3";


        //$where = array('r_status'=>'1','status'=>'0','state'=>'1','x>'=>0,'y>'=>0);
        
         $where="`r_status`='1' and `status`='0' and `state`='1' and `x`>0 and `y`>0 ";


        if($_SESSION['daopin']['job_classid']){
 
           $where.=" and (`job1` in({$_SESSION['daopin']['job_classid']}) or `job1_son` in({$_SESSION['daopin']['job_classid']}) or`job_post` in({$_SESSION['daopin']['job_classid']}))"; 

        }

        if($_SESSION['daopin']['city_classid']){
 
           $where.=" and (`provinceid` in({$_SESSION['daopin']['city_classid']}) or `cityid` in({$_SESSION['daopin']['city_classid']}) or `three_cityid` in({$_SESSION['daopin']['city_classid']})) "; 

        }


        if($_SESSION['daopin']['minsalary']>0 && $_SESSION['daopin']['maxsalary']>0){

           $where.=" and `minsalary`>='{$_SESSION['daopin']['minsalary']}' and `maxsalary`>='{$_SESSION['daopin']['maxsalary']}'"; 

        }


        if ($this->config['did']){
            //$where['did']=$this->config['did'];           
            $where.=" and did={$this->config['did']}";
        }


        //过滤屏蔽额职位和企业

        if($_COOKIE['closecom'] && !empty($_COOKIE['closecom'])){

            $where.=" and uid not in({$_COOKIE['closecom']})";

        }

        if($_COOKIE['closejob'] && !empty($_COOKIE['closejob'])){

            $where.=" and id not in({$_COOKIE['closejob']})";

        }


        //echo $where.'<br/>-----';

        //查询职位
        //$rows=$JobM->GetComjobList($where,array('field'=>$select,'limit'=>$limit,'orderby'=>'distance','desc'=>'asc'));

        $rows=$this->obj->DB_select_all("company_job",$where.' order by distance asc limit '.$limit,$select);



         //print_R($rows);exit;


        if ($rows){
            foreach ($rows as $v){
                $uids[]=$v['uid'];
            }
            $CompanyM=$this->MODEL('company');

            //获取企业
            $com = $CompanyM->GetComList(array("`uid` in (".pylode(',', $uids).")"),array('field'=>'`uid`,`name`,`shortname`,`welfare`,`address`,`logo`,`hy`,`pr`,`mun`'));



            foreach ($rows as $k=>$v){
                $list[$k]['id']      =$v['id'];

                $list[$k]['uid'] = $v['uid']; //hjl add



                $list[$k]['name']    =mb_substr($v['name'], 0,16,'utf-8');
                if ($v['minsalary']){
                    if ($v['maxsalary']>0){
                        $list[$k]['salary_n']='￥'.$v['minsalary'].'-'.$v['maxsalary'];
                    }else{
                        $list[$k]['salary_n']='￥'.$v['minsalary'].'以上';
                    }
                }else{
                    $list[$k]['salary_n']='面议';
                }
                if($v['distance']<=1){
                    $list[$k]['dis']=ceil($v['distance']*1000).'m';
                }else{
                    $list[$k]['dis']=round($v['distance'], 2).'km';
                }
                $list[$k]['joburl']  =Url('wap',array('c'=>'job','a'=>'view','id'=>$v['id']));
                $list[$k]['comurl']  =Url('wap',array('c'=>'company','a'=>'show','id'=>$v['uid']));
                $list[$k]['addressurl']  =Url('wap',array('c'=>'map','a'=>'jobmap','id'=>$v['uid']));

                $list[$k]['lastupdate'] = date('Y-m-d',$v['lastupdate']);

                $province_info = $this->obj->DB_select_once(
                   "city_class",
                   "`id`='{$v['provinceid']}'"
                );

                $city_info = $this->obj->DB_select_once(
                   "city_class",
                   "`id`='{$v['cityid']}'"
                );


                $list[$k]['province_name'] =  $province_info['name'];
                $list[$k]['city_name']     =  $city_info['name'];

                 $expinfo =  $this->obj->DB_select_once(
                   "comclass",
                   "`id`='{$v['exp']}'",'name'
                );


                $list[$k]['exp'] =$expinfo['name'];

               $eduinfo = $this->obj->DB_select_once(
                   "comclass",
                   "`id`='{$v['edu']}'",'name'
                );

                $list[$k]['edu'] =$eduinfo['name'];

                $label_names=$this->obj->DB_select_all("comclass","`id` in({$v['label']})");
                $job_label_arr= array();
                if(is_array($label_names) && !empty($label_names)){
                    foreach($label_names as $v1){

                     $job_label_arr[] = $v1['name'];

                    }
                }
 
                $list[$k]['job_label'] = $job_label_arr;

                $list[$k]['bounty']   =  $v['bounty'];
                $list[$k]['job_pay']   =  $v['job_pay'];


                foreach ($com as $val){
                    if ($val['uid']==$v['uid']) {
                        if($v['shortname']){
                            $list[$k]['com_name']=mb_substr($val['shortname'], 0,16,'utf-8');
                        }else{
                            $list[$k]['com_name']=mb_substr($val['name'], 0,16,'utf-8');
                        }
                        if($v['welfare']){
                            $list[$k]['welfare']=@explode(",",$val['welfare']);
                        }
                        $list[$k]['address']=$val['address'];
                        $list[$k]['com_logo'] = $this->config['sy_weburl'].'/'.trim($val['logo'],'.');

                        $list[$k]['pr_n'] = $cache_array['comclass_name'][$val['pr']];
                        $list[$k]['hy_n'] = $cache_array['industry_name'][$val['hy']];
                        $list[$k]['mun_n'] = $cache_array['comclass_name'][$val['mun']];


                    }
                }
            }


        }
        
        $jobnum = $JobM->GetComjobNum(array('r_status'=>'1','status'=>'0','state'=>'1','x>'=>0,'y>'=>0));  //获取记录总数

        

        $pagecount = ceil($jobnum/10);
        if ($this->config['sy_indexpage']){
            $indexpagenum = ceil($this->config['sy_indexpage']/10);
            if($pagecount>$indexpagenum){
                $pagecount=$indexpagenum;
            }
        }



        $data['list']=count($list)>0?$list:array();
        $prev='';
        if($page>1){
            $prev=Url('wap',array('c'=>'map','page'=>$page-1,'x'=>$_POST['x'],'y'=>$_POST['y']));
        }
        //$option="";
        /*for ($x=1; $x<=$pagecount; $x++) {
            $selected = '';
            if ($x==$page){
                $selected= "selected='selected'";
            }
            $option .= "<option value='".Url('wap',array('c'=>'map','page'=>$x,'x'=>$_POST['x'],'y'=>$_POST['y']))."' ".$selected.">".$x."</option>";
        } */



        if($pagecount>$page){
            //echo $_POST['x'];exit;
            //$next=Url('wap',array('c'=>'map','page'=>$page+1,'x'=>$_POST['x'],'y'=>$_POST['y']));
        }

        $data['prev']=$prev;
        //$data['next']=$next;
        $data['option']=$option;
        $data['pagecount']=$pagecount;
        $data['error']=0;
        echo json_encode($data);die;
	}


    
    //hjl 获取附近赏金工作
    function rewardJoblist_action(){

         global $db;
         $cache_array = $db->cacheget();
		$this->get_moblie();
        $JobM=$this->MODEL('job');
        
        $select="`id`,`uid`,`name`,`minsalary`,`maxsalary`,`lastupdate`,`provinceid`,`cityid`,`exp`,`edu`,`label`,6371 * acos(cos(radians(".$_POST['y'].")) * cos(radians(`y`)) * cos(radians(`x`) - radians(".$_POST['x'].")) + sin(radians(".$_POST['y'].")) * sin(radians(`y`))) AS `distance`,`bounty`,`job_pay`";



        $page = $_POST['page']?$_POST['page']:1;
        if ($this->config['sy_indexpage']){
            $indexpagenum = ceil($this->config['sy_indexpage']/10);
            if($page>$indexpagenum){
                $page=$indexpagenum;
            }
        }
        $pagenav=($page-1)*3;
        $limit="$pagenav,3";

        //$where = array('r_status'=>'1','status'=>'0','state'=>'1','x>'=>0,'y>'=>0,'job_pay>'=>0);

        $where="`r_status`='1' and `status`='0' and `state`='1' and `x`>0 and `y`>0 and `job_pay`>0 and bounty>0 ";
        if($_SESSION['daopin']['job_classid']){
 
           $where.=" and (`job1` in({$_SESSION['daopin']['job_classid']}) or `job1_son` in({$_SESSION['daopin']['job_classid']}) or`job_post` in({$_SESSION['daopin']['job_classid']}))"; 

        }

        if($_SESSION['daopin']['city_classid']){
 
           $where.=" and (`provinceid` in({$_SESSION['daopin']['city_classid']}) or `cityid` in({$_SESSION['daopin']['city_classid']}) or `three_cityid` in({$_SESSION['daopin']['city_classid']})) "; 

        }


        if($_SESSION['daopin']['minsalary']>0 && $_SESSION['daopin']['maxsalary']>0){

           $where.=" and `minsalary`>='{$_SESSION['daopin']['minsalary']}' and `maxsalary`>='{$_SESSION['daopin']['maxsalary']}'"; 

        }



        if ($this->config['did']){

            $where.=" and did={$this->config['did']}";
        }


        //$rows=$JobM->GetComjobList($where,array('field'=>$select,'limit'=>$limit,'orderby'=>'distance','desc'=>'asc'));
         $rows=$this->obj->DB_select_all("company_job",$where.' order by distance asc limit '.$limit,$select);
         


        if ($rows){
            foreach ($rows as $v){
                $uids[]=$v['uid'];
            }
            $CompanyM=$this->MODEL('company');
            $com = $CompanyM->GetComList(array("`uid` in (".pylode(',', $uids).")"),
                array('field'=>'`uid`,`name`,`shortname`,`welfare`,`address`,`logo`,`hy`,`pr`,`mun`'));

            foreach ($rows as $k=>$v){
                $list[$k]['id']      =$v['id'];
                $list[$k]['uid'] = $v['uid']; //hjl add
                $list[$k]['name']    =mb_substr($v['name'], 0,16,'utf-8');
                if ($v['minsalary']){
                    if ($v['maxsalary']>0){
                        $list[$k]['salary_n']='￥'.$v['minsalary'].'-'.$v['maxsalary'];
                    }else{
                        $list[$k]['salary_n']='￥'.$v['minsalary'].'以上';
                    }
                }else{
                    $list[$k]['salary_n']='面议';
                }
                if($v['distance']<=1){
                    $list[$k]['dis']=ceil($v['distance']*1000).'m';
                }else{
                    $list[$k]['dis']=round($v['distance'], 2).'km';
                }
                $list[$k]['joburl']  =Url('wap',array('c'=>'job','a'=>'view','id'=>$v['id']));
                $list[$k]['comurl']  =Url('wap',array('c'=>'company','a'=>'show','id'=>$v['uid']));
                $list[$k]['addressurl']  =Url('wap',array('c'=>'map','a'=>'jobmap','id'=>$v['uid']));

                $list[$k]['lastupdate'] = date('Y-m-d',$v['lastupdate']);

                $province_info = $this->obj->DB_select_once(
                   "city_class",
                   "`id`='{$v['provinceid']}'"
                );

                $city_info = $this->obj->DB_select_once(
                   "city_class",
                   "`id`='{$v['cityid']}'"
                );


                $list[$k]['province_name'] =  $province_info['name'];
                $list[$k]['city_name']     =  $city_info['name'];

                 $expinfo = $this->obj->DB_select_once(
                   "comclass",
                   "`id`='{$v['exp']}'",'name'
                );

                 $list[$k]['exp'] = $expinfo['name'];
                 $eduinfo = $this->obj->DB_select_once(
                   "comclass",
                   "`id`='{$v['edu']}'",'name');

                $list[$k]['edu'] =  $eduinfo['name'];

                $label_names=$this->obj->DB_select_all("comclass","`id` in({$v['label']})");
                $job_label_arr= array();
                if(is_array($label_names) && !empty($label_names)){
                    foreach($label_names as $v1){

                     $job_label_arr[] = $v1['name'];

                    }
                }
 
                $list[$k]['job_label'] = $job_label_arr;

                $list[$k]['bounty']   =  $v['bounty'];
                $list[$k]['job_pay']   =  $v['job_pay'];


                foreach ($com as $val){
                    if ($val['uid']==$v['uid']) {
                        if($v['shortname']){
                            $list[$k]['com_name']=mb_substr($val['shortname'], 0,16,'utf-8');
                        }else{
                            $list[$k]['com_name']=mb_substr($val['name'], 0,16,'utf-8');
                        }
                        if($v['welfare']){
                            $list[$k]['welfare']=@explode(",",$val['welfare']);
                        }
                        $list[$k]['address']=$val['address'];
                        $list[$k]['com_logo'] = $this->config['sy_weburl'].'/'.trim($val['logo'],'.');

                        $list[$k]['pr_n'] = $cache_array['comclass_name'][$val['pr']];
                        $list[$k]['hy_n'] = $cache_array['industry_name'][$val['hy']];
                        $list[$k]['mun_n'] = $cache_array['comclass_name'][$val['mun']];


                    }
                }
            }
        }
        
        $jobnum = $JobM->GetComjobNum(array('r_status'=>'1','status'=>'0','state'=>'1','x>'=>0,'y>'=>0));
        $pagecount = ceil($jobnum/10);
        if ($this->config['sy_indexpage']){
            $indexpagenum = ceil($this->config['sy_indexpage']/10);
            if($pagecount>$indexpagenum){
                $pagecount=$indexpagenum;
            }
        }
        
        $data['list']=count($list)>0?$list:array();
        $prev='';
        if($page>1){
            $prev=Url('wap',array('c'=>'map','page'=>$page-1,'x'=>$_POST['x'],'y'=>$_POST['y']));
        }
        //$option="";
        /*for ($x=1; $x<=$pagecount; $x++) {
            $selected = '';
            if ($x==$page){
                $selected= "selected='selected'";
            }
            $option .= "<option value='".Url('wap',array('c'=>'map','page'=>$x,'x'=>$_POST['x'],'y'=>$_POST['y']))."' ".$selected.">".$x."</option>";
        } */
        /*if($pagecount>$page){
            $next=Url('wap',array('c'=>'map','page'=>$page+1,'x'=>$_POST['x'],'y'=>$_POST['y']));
        }*/
        $data['prev']=$prev;
        //$data['next']=$next;
        $data['option']=$option;
        $data['pagecount']=$pagecount;
        $data['error']=0;
        echo json_encode($data);die;
	}
    








}
?>